import os
import sys

class treelist():
    # def __init__(self):
    #     self.t_id = 1
    #     self.c_id = 0
    #     self.t_pid = 0
    #     self.t_list = []

    def getList(self, dir, layer, id, pid, treelist):
        pid = id
        for i in range(layer):
            id = id * 100
        if (layer == 0):
            treelist.append({"id": 1, "pId": 0, "name": dir.split('\\')[-1], "status": 0, "open": True})

        # 对目录下的文件列表进行排序
        files = os.listdir(dir)

        for file in files:
            id += 1
            treejson = {}
            if (file[0] == '.'):
                continue
            file = os.path.join(dir, file)
            if os.path.isdir(file):
                #
                status = 0
                treejson["id"] = id
                treejson["pId"] = pid
                treejson["name"] = file.split('\\')[-1]
                treejson["status"] = status
                treelist.append(treejson)
                self.getList(file, layer + 1, id, 0, treelist)
            else:
                status = 1
                treejson["id"] = id
                treejson["pId"] = pid
                treejson["name"] = file.split('\\')[-1]
                treejson["status"] = status
                treelist.append(treejson)
        return treelist

